package com.shexianyu.simple;

public class FindTilt {
    int res = 0;

    public int findTilt(TreeNode root) {
        dfs(root);
        return res;
    }

    public int dfs(TreeNode node) {
        if (node == null) {
            return 0;
        }
        int sumLeft = dfs(node.left);
        int sumRight = dfs(node.right);
        res += Math.abs(sumLeft - sumRight);
        return sumLeft + sumRight + node.val;
    }

}

